#ifndef _UDP_SERVER_H_
#define _UDP_SERVER_H_
#include "crossplat_def.h"
#include "protocol_info.h"
#include "dvr_cmd.h"
#ifdef _WIN32
#else
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif
#include <thread>

class CUdpSvrSocket
{
public:

	CUdpSvrSocket();
	~CUdpSvrSocket();

	int Init(int send_buf_sz,int portNum);
//	int StartCmdStrl(SOCKET clntSock);
	int Start();
	int ListenProc();
	void CloseSock(SOCKET sock);
	int IoctrlSock(SOCKET sock, long cmd,unsigned long * argp);
// 	CMD_CLIENT_INFO_S * GetFreeClientInfo(SOCKET sock);
// 	void DestroyClient(SOCKET sock);

	int GetSocket()
	{
		return (int)m_sock;
	}
	int GetIpaddrInfo(SOCKET fd, sockaddr_in );;
	static int PUB_THREAD_CALL CmdServerUdpProcThread(void *pParam);
protected:
	unsigned char * m_rcvBuf;
	int             m_rcvBuf_sz;

	unsigned char * m_outBuf;
	int             m_send_sz;
	CDVRCmd        m_dvrCnd;
	struct sockaddr_in m_servaddr;
	int             m_client_max;
	SOCKET		    m_sock;
	SOCKET			m_socks[1024];
	fd_set			 m_fds;
	//cross_thread_t m_dataThdID;
	std::thread    m_thd;
};


#endif //_DVR_CMD_APP_H_
